package com.yxy.resp;

import com.yxy.type.CodeStatusEnum;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author 杨芯叶
 * @Create 2025-07-25-09:49
 * @Message
 **/
@Data
@ToString
@NoArgsConstructor
public class Result<T> {
    private boolean success;
    private int code;
    private String message;
    private T data;

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<T>();
        result.success = true;
        result.data = data;
        result.code = 200;
        result.message = "操作成功";
        return result;
    }

    public static <T> Result<T> success(String message) {
        Result<T> result = new Result<>();
        result.success = true;
        result.data = null;
        result.code = 200;
        result.message = message;
        return result;
    }

    public static <T> Result<T> success( String message,T data) {
        Result<T> result = new Result<T>();
        result.success = true;
        result.data = data;
        result.code = 200;
        result.message = message;
        return result;
    }

    public static <T> Result<T> success(CodeStatusEnum errorCode) {
        Result<T> result = new Result<T>();
        result.success = true;
        result.data = null;
        result.code = errorCode.getCode();
        result.message = errorCode.getMessage();
        return result;
    }

    public static <T> Result<T> success(T data, CodeStatusEnum errorCode) {
        Result<T> result = new Result<T>();
        result.success = true;
        result.data = data;
        result.code = errorCode.getCode();
        result.message = errorCode.getMessage();
        return result;
    }

    public static <T> Result<T> fail(CodeStatusEnum errorCode) {
        Result<T> result = new Result<T>();
        result.success = false;
        result.code = errorCode.getCode();
        result.message = errorCode.getMessage();
        return result;
    }

    public static <T> Result<T> fail(CodeStatusEnum errorCode, String message) {
        Result<T> result = new Result<T>();
        result.success = false;
        result.code = errorCode.getCode();
        result.message = errorCode.getMessage() + ": " + message;
        return result;
    }

}
